import random

def generate_reachable_array(length=10):
    """生成一个确保可以跳到最后的数组"""
    nums = [0] * length
    current_pos = length - 1

    while current_pos > 0:
        # 随机选择前面的一个位置
        jump_from = random.randint(0, current_pos - 1)
        # 确保从该位置能跳到current_pos
        min_jump = current_pos - jump_from
        nums[jump_from] = random.randint(min_jump, min_jump + 3)
        current_pos = jump_from

    # 填充其余位置的随机数
    for i in range(length):
        if nums[i] == 0 and i != length - 1:
            nums[i] = random.randint(1, 5)

    return nums

def generate_unreachable_array(length=10):
    """生成一个无法跳到最后的数组"""
    nums = [random.randint(1, 3) for _ in range(length)]
    # 在中间某个位置放置0，使得无法到达终点
    zero_pos = random.randint(1, length - 2)
    nums[zero_pos] = 0
    # 确保前面的数字无法越过这个0
    for i in range(zero_pos):
        nums[i] = min(nums[i], zero_pos - i)
    return nums

def generate_test_cases(num_cases=100):
    test_cases = []

    # 生成可以到达终点的测试用例
    for _ in range(num_cases // 2):
        length = random.randint(5, 20)
        test_cases.append((generate_reachable_array(length), True))

    # 生成不可到达终点的测试用例
    for _ in range(num_cases // 2):
        length = random.randint(5, 20)
        test_cases.append((generate_unreachable_array(length), False))

    # 添加一些特殊测试用例
    special_cases = [
        ([2,3,1,1,4], True),     # 基本可达用例
        ([3,2,1,0,4], False),    # 基本不可达用例
        ([0], True),             # 单元素数组
        ([1,0], True),           # 两个元素，可达
        ([0,2], False),          # 两个元素，不可达
        ([2,0,0], True),         # 可以跨过0到达终点
        ([1,0,1,0], False),      # 中间有0阻隔
    ]
    test_cases.extend(special_cases)

    # 将测试用例写入文件
    with open('input3.txt', 'w') as f:
        f.write(f"{len(test_cases)}\n")
        for nums, expected in test_cases:
            f.write(f"{','.join(map(str, nums))}\n{expected}\n")

if __name__ == '__main__':
    generate_test_cases()
